package cn.stylefeng.guns.modular.gridsystem.temperature.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.base.param.BaseParam;
import cn.stylefeng.guns.core.pojo.page.PageResult;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.modular.gridsystem.temperature.model.param.BizTemperatureConfigParam;
import cn.stylefeng.guns.modular.gridsystem.temperature.model.result.BizTemperatureConfigResult;
import cn.stylefeng.guns.modular.gridsystem.temperature.service.BizTemperatureConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BizTemperatureConfigController {

    @Autowired
    private BizTemperatureConfigService bizTemperatureConfigService;


    /**
     * 添加
     *
     * @param param
     * @return
     */
    @PostMapping("/temperature/config/add")
    @BusinessLog(title = "biz_temperature_config_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated({BizTemperatureConfigParam.add.class}) BizTemperatureConfigParam param) {

        Integer id = bizTemperatureConfigService.toAdd(param);
        if (id !=null) {
            return new SuccessResponseData(200, "添加成功", id);
        }
        return new SuccessResponseData(501, "添加失败", null);
    }

    /**
     * 编辑
     *
     * @param param
     * @return
     */
    @PostMapping("/temperature/config/editValue")
    @BusinessLog(title = "biz_temperature_config_修改", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData editValue(@RequestBody @Validated({BizTemperatureConfigParam.edit.class}) BizTemperatureConfigParam param) {
        return new SuccessResponseData( bizTemperatureConfigService.toEditValue(param));
    }

    /**
     * 删除
     *
     * @param param
     * @return
     */
    @PostMapping("/temperature/config/delete")
    @BusinessLog(title = "biz_temperature_config_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated({BaseParam.delete.class}) BizTemperatureConfigParam param) {

//        bizTemperatureConfigService.toDelete(param);
        return new SuccessResponseData();
    }

    /**
     *
     * @param param
     * @return
     */
    @GetMapping("/temperature/config/selectPage")
    @BusinessLog(title = "biz_temperature_config_分页查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData selectPage(BizTemperatureConfigParam param) {
        PageResult<BizTemperatureConfigResult> bizTemperatureConfigResultPageResult= bizTemperatureConfigService.selectPage(param);
        return new SuccessResponseData(bizTemperatureConfigResultPageResult);
    }

}
